home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTPtrDlist.z / RWTPtrDlist
Encoding:
Text File  |  2002-10-03  |  21.3 KB  |  595 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTPtrDlist<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tpdlist.h>
  13.  
  14.  
  15.  
  16.               RWTPtrDlist<T> list;
  17.  
  18. PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!!
  19.      IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd
  20.      hhhheeeerrrreeee....  OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt described in the Class
  21.      Reference.
  22.  
  23.  
  24. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  25.      This class maintains a collection of pointers to type TTTT, implemented as a
  26.      doubly linked list.  This is a pointer based list: pointers to objects
  27.      are copied in and out of the links that make up the list. Parameter TTTT
  28.      represents the type of object to be inserted into the list, either a
  29.      class or fundamental type.  The class TTTT must have:
  30.           well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))).
  31.  
  32.  
  33. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  34.      Isomorphic
  35.  
  36. EEEExxxxaaaammmmpppplllleeee
  37.      In this example, a doubly-linked list of pointers to the user type DDDDoooogggg is
  38.      exercised.  Contrast this approach with the example given under
  39.      RRRRWWWWTTTTVVVVaaaallllDDDDlllliiiisssstttt<<<<TTTT>>>>....
  40.  
  41.               #include <rw/tpdlist.h>
  42.           #include <rw/rstream.h>
  43.           #include <string.h>
  44.           class Dog {
  45.             char* name;
  46.           public:
  47.             Dog( const char* c) {
  48.               name = new char[strlen(c)+1];
  49.               strcpy(name, c);
  50.             }
  51.             ~Dog() { delete name; }
  52.             // Define a copy constructor:
  53.             Dog(const Dog& dog) {
  54.               name = new char[strlen(dog.name)+1];
  55.               strcpy(name, dog.name);
  56.             }
  57.             // Define an assignment operator:
  58.             void operator=(const Dog& dog) {
  59.               if (this!=&dog) {
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               delete name;
  75.               name = new char[strlen(dog.name)+1];
  76.               strcpy(name, dog.name);
  77.               }
  78.             }
  79.             // Define an equality test operator:
  80.             int operator==(const Dog& dog) const {
  81.               return strcmp(name, dog.name)==0; }
  82.             friend ostream& operator<<(ostream& str, const Dog& dog){
  83.               str << dog.name;
  84.               return str;}
  85.           };
  86.           main()  {
  87.             RWTPtrDlist<Dog> terriers;
  88.             terriers.insert(new Dog("Cairn Terrier"));
  89.             terriers.insert(new Dog("Irish Terrier"));
  90.             terriers.insert(new Dog("Schnauzer"));
  91.             Dog key1("Schnauzer");
  92.             cout << "The list "
  93.                  << (terriers.contains(&key1) ? "does " : "does not ")
  94.                  << "contain a Schnauzer0;
  95.             Dog key2("Irish Terrier");
  96.             terriers.insertAt(
  97.                 terriers.index(&key2),
  98.                 new Dog("Fox Terrier")
  99.               );
  100.             Dog* d;
  101.             while (!terriers.isEmpty()) {
  102.               d = terriers.get();
  103.               cout << *d << endl;
  104.               delete d;
  105.             }
  106.             return 0;
  107.           }
  108.  
  109.  
  110.      Program output:
  111.  
  112.               The list does contain a Schnauzer
  113.  
  114.  
  115.  
  116.               Cairn Terrier
  117.           Fox Terrier
  118.           Irish Terrier
  119.           Schnauzer
  120.  
  121. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  122.               RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt<T>();
  123.  
  124.  
  125.      Constructs an empty list.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt<T>(const RWTPtrDlist<T>& c);
  141.  
  142.  
  143.      Constructs a new doubly-linked list as a shallow copy of cccc.  After
  144.      construction, pointers will be shared between the two collections.
  145.  
  146. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss
  147.               RWTPtrDlist&
  148.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrDlist<T>& c);
  149.  
  150.  
  151.      Sets self to a shallow copy of cccc.  Afterwards, pointers will be shared
  152.      between the two collections.
  153.  
  154.               T*&
  155.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i);
  156.           T* const&
  157.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const;
  158.  
  159.  
  160.      Returns a pointer to the iiiith value in the list.  The first variant can be
  161.      used as an llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero
  162.      and the number of items in the collection less one, or an exception of
  163.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  164.  
  165. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  166.               void
  167.           aaaappppppppeeeennnndddd(T* a);
  168.  
  169.  
  170.      Appends the item pointed to by aaaa to the end of the list.
  171.  
  172.               void
  173.           aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d);
  174.  
  175.  
  176.      Applies the user-defined function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in
  177.      the list.  This function must have the prototype:
  178.  
  179.               void yyyyoooouuuurrrrFFFFuuuunnnn(T* a, void* d);
  180.  
  181.  
  182.  
  183.  
  184.  
  185.      This function will be called for each item in the list, with a pointer to
  186.      the item as the first argument.  Client data may be passed through as
  187.      parameter dddd.
  188.  
  189.               T*&
  190.           aaaatttt(size_t i);
  191.           T* const&
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.           aaaatttt(size_t i) const;
  207.  
  208.  
  209.      Returns a pointer to the iiiith value in the list.  The first variant can be
  210.      used as an llllvvvvaaaalllluuuueeee, the second cannot.  The index iiii must be between zero
  211.      and the number of items in the collection less one, or an exception of
  212.      type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  213.  
  214.               void
  215.           cccclllleeeeaaaarrrr();
  216.  
  217.  
  218.      Removes all items from the collection.
  219.  
  220.               void
  221.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  222.  
  223.  
  224.      Removes all items from the collection aaaannnndddd deletes them.
  225.  
  226.               RWBoolean
  227.           ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const;
  228.  
  229.  
  230.      Returns TTTTRRRRUUUUEEEE if the list contains an object that is equal to the object
  231.      pointed to by aaaa, FFFFAAAALLLLSSSSEEEE otherwise.  Equality is measured by the class-
  232.      defined equality operator for type TTTT.
  233.  
  234.               RWBoolean
  235.           ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(T*, void*),void* d) const;
  236.  
  237.  
  238.      Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined
  239.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  Returns FFFFAAAALLLLSSSSEEEE
  240.      otherwise.  The tester function must have the prototype:
  241.  
  242.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  243.  
  244.  
  245.  
  246.  
  247.  
  248.      This function will be called for each item in the list, with a pointer to
  249.      the item as the first argument.  Client data may be passed through as
  250.      parameter dddd.
  251.  
  252.               size_t
  253.           eeeennnnttttrrrriiiieeeessss() const;
  254.  
  255.  
  256.      Returns the number of items that are currently in the collection.
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               T*
  273.           ffffiiiinnnndddd(const T* target) const;
  274.  
  275.  
  276.      Returns a pointer to the first object encountered which is equal to the
  277.      object pointed to by ttttaaaarrrrggggeeeetttt, or nnnniiiillll if no such object can be found.
  278.      Equality is measured by the class-defined equality operator for type TTTT.
  279.  
  280.               T*
  281.           ffffiiiinnnndddd(RWBoolean (*testFun)(T*, void*),void* d,) const;
  282.  
  283.  
  284.      Returns a pointer to the first object encountered for which the user-
  285.      defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if no
  286.      such object can be found.  The tester function must have the prototype:
  287.  
  288.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  289.  
  290.  
  291.  
  292.  
  293.  
  294.      This function will be called for each item in the list, with a pointer to
  295.      the item as the first argument.  Client data may be passed through as
  296.      parameter dddd.
  297.  
  298.               T*&
  299.           ffffiiiirrrrsssstttt();
  300.           T* const&
  301.           ffffiiiirrrrsssstttt() const;
  302.  
  303.  
  304.      Returns a pointer to the first item in the list.  The behavior is
  305.      undefined if the list is empty.
  306.  
  307.               T*
  308.           ggggeeeetttt();
  309.  
  310.  
  311.      Returns a pointer to the first item in the list and removes the item.
  312.      The behavior is undefined if the list is empty.
  313.  
  314.               size_t
  315.           iiiinnnnddddeeeexxxx(const T* a);
  316.  
  317.  
  318.      Returns the index of the first object that is equal to the object pointed
  319.      to by aaaa, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object.  Equality is measured by
  320.      the class-defined equality operator for type TTTT.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               size_t
  339.           iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(T*, void*),void* d) const;
  340.  
  341.  
  342.      Returns the index of the first object for which the user-defined tester
  343.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no
  344.      such object.  The tester function must have the prototype:
  345.  
  346.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  347.  
  348.  
  349.  
  350.  
  351.  
  352.      This function will be called for each item in the list, with a pointer to
  353.      the item as the first argument.  Client data may be passed through as
  354.      parameter dddd.
  355.  
  356.               void
  357.           iiiinnnnsssseeeerrrrtttt(T* a);
  358.  
  359.  
  360.      Adds the object pointed to by aaaa to the end of the list.
  361.  
  362.               void
  363.           iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a);
  364.  
  365.  
  366.      Adds the object pointed to by aaaa at the index position iiii.  This position
  367.      must be between zero and the number of items in the list, or an exception
  368.      of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown.
  369.  
  370.               RWBoolean
  371.           iiiissssEEEEmmmmppppttttyyyy() const;
  372.  
  373.  
  374.      Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise.
  375.  
  376.               T*&
  377.           llllaaaasssstttt();
  378.           T* const&
  379.           llllaaaasssstttt() const;
  380.  
  381.  
  382.      Returns a pointer to the last item in the list.  The behavior is
  383.      undefined if the list is empty.
  384.  
  385.               size_t
  386.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const;
  387.  
  388.  
  389.      Returns the number of objects in the list that are equal to the object
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      pointed to by aaaa.  Equality is measured by the class-defined equality
  405.      operator for type TTTT.
  406.  
  407.               size_t
  408.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(T*, void*),void* d)const;
  409.  
  410.  
  411.      Returns the number of objects in the list for which the user-defined
  412.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  The tester
  413.      function must have the prototype:
  414.  
  415.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  416.  
  417.  
  418.  
  419.  
  420.  
  421.      This function will be called for each item in the list, with a pointer to
  422.      the item as the first argument.  Client data may be passed through as
  423.      parameter dddd.
  424.  
  425.               void
  426.           pppprrrreeeeppppeeeennnndddd(T* a);
  427.  
  428.  
  429.      Adds the item pointed to by aaaa to the beginning of the list.
  430.  
  431.               T*
  432.           rrrreeeemmmmoooovvvveeee(const T* a);
  433.  
  434.  
  435.      Removes the first object which is equal to the object pointed to by aaaa and
  436.      returns a pointer to it, or nnnniiiillll if no such object could be found.
  437.      Equality is measured by the class-defined equality operator for type TTTT.
  438.  
  439.               T*
  440.           rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(T*, void*),void* d);
  441.  
  442.  
  443.      Removes the first object for which the user-defined tester function
  444.      pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE and returns a pointer to it, or nnnniiiillll if
  445.      there is no such object.  The tester function must have the prototype:
  446.  
  447.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  448.  
  449.  
  450.  
  451.  
  452.  
  453.      This function will be called for each item in the list, with a pointer to
  454.      the item as the first argument.  Client data may be passed through as
  455.      parameter dddd.
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  467.  
  468.  
  469.  
  470.               size_t
  471.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a);
  472.  
  473.  
  474.      Removes all objects which are equal to the object pointed to by aaaa.
  475.      Returns the number of objects removed.  Equality is measured by the
  476.      class-defined equality operator for type TTTT.
  477.  
  478.               size_t
  479.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(RWBoolean (*testFun)(T*, void*),void* d);
  480.  
  481.  
  482.      Removes all objects for which the user-defined tester function pointed to
  483.      by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  Returns the number of objects removed.  The
  484.      tester function must have the prototype:
  485.  
  486.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d);
  487.  
  488.  
  489.  
  490.  
  491.  
  492.      This function will be called for each item in the list, with a pointer to
  493.      the item as the first argument.  Client data may be passed through as
  494.      parameter dddd.
  495.  
  496.               T*
  497.           rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i);
  498.  
  499.  
  500.      Removes the object at index iiii and returns a pointer to it.  An exception
  501.      of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index.  Valid
  502.      indices are from zero to the number of items in the list less one.
  503.  
  504.               T*
  505.           rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt();
  506.  
  507.  
  508.      Removes the first item in the list and returns a pointer to it.  The
  509.      behavior is undefined if the list is empty.
  510.  
  511.               T*
  512.           rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt();
  513.  
  514.  
  515.      Removes the last item in the list and returns a pointer to it.  The
  516.      behavior is undefined if the list is empty.
  517.  
  518. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  519.               RWvostream&
  520.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrDlist<T>& coll);
  521.           RWFile&
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTPPPPttttrrrrDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  533.  
  534.  
  535.  
  536.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrDlist<T>& coll);
  537.  
  538.  
  539.      Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to
  540.      it if it has already been saved.
  541.  
  542.               RWvistream&
  543.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrDlist<T>& coll);
  544.           RWFile&
  545.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrDlist<T>& coll);
  546.  
  547.  
  548.      Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm.
  549.  
  550.               RWvistream&
  551.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrDlist<T>*& p);
  552.           RWFile&
  553.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrDlist<T>*& p);
  554.  
  555.  
  556.      Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a
  557.      new collection off the heap and sets pppp to point to it, or sets pppp to point
  558.      to a previously read instance.  If a collection is created off the heap,
  559.      then you are responsible for deleting it.
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.